package Lab08;

import java.util.ArrayList;
import java.util.Collection;

//8_4
public class Course {
    private String courseName;
    //  private String[] students = new String[100];
    private ArrayList<String> students = new ArrayList<>();
    private int numberOfStudents;

    public Course(String courseName) {
        this.courseName = courseName;
    }

    public void addStudent(String student) {
//    students[numberOfStudents] = student;
        numberOfStudents++;
        students.add(student);
    }

//  public String[] getStudents() {
//    return students;
//  }

    public ArrayList<String> getStudents() {
        return students;
    }

    public int getNumberOfStudents() {
        return numberOfStudents;
    }

    public String getCourseName() {
        return courseName;
    }

    public void dropStudent(String student) {
        // Left as an exercise in Exercise 9.9
    }

    public static void main(String[] args) {
        Course course1 = new Course("course1");
        Course course2 = new Course("course2");
        course1.addStudent("Peter Jones");
//    Peter Jones Brian Smith Anne Kennedy
//    Peter Jones Steve Smith
        course1.addStudent("Brian Smith");
        course1.addStudent("Anne Kennedy");

        course2.addStudent("Peter Jones");
        course2.addStudent("Steve Smith");

        System.out.println("Number of students in " + course1.getCourseName() + " : " + course1.getNumberOfStudents());
        ArrayList<String> students = course1.getStudents();
        for (String student : students) {
            System.out.print(student + "  ");
        }
        System.out.println();

        System.out.println("Number of students in " + course2.getCourseName() + " : " + course2.getNumberOfStudents());
        Collection<String> students2 = course2.getStudents();
        for (String student : students2) {
            System.out.print(student + "  ");
        }
        System.out.println();


    }
}

class  Main{
    public static void main(String[] args) {
        Course course1 = new Course("course1");
        Course course2 = new Course("course2");
        course1.addStudent("Peter Jones");
//    Peter Jones Brian Smith Anne Kennedy
//    Peter Jones Steve Smith
        course1.addStudent("Brian Smith");
        course1.addStudent("Anne Kennedy");

        course2.addStudent("Peter Jones");
        course2.addStudent("Steve Smith");

        System.out.println("Number of students in " + course1.getCourseName() + " : " + course1.getNumberOfStudents());
        ArrayList<String> students = course1.getStudents();
        for (String student : students) {
            System.out.print(student + "  ");
        }
        System.out.println();

        System.out.println("Number of students in " + course2.getCourseName() + " : " + course2.getNumberOfStudents());
        Collection<String> students2 = course2.getStudents();
        for (String student : students2) {
            System.out.print(student + "  ");
        }
        System.out.println();
    }
}
